package com.leyou.page.controller;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @author: guojy
 * @date: 2020/3/10 19:00
 * @Description:
 * @version: 1.0
 */
@Controller
public class PageController {
    @Autowired
    private PageService pageService;

    /**
     * 根据 spuid，查询数据
     *
     * @param id
     * @param model
     * @return
     */
    @GetMapping("/item/{id}.html")
    public String toItemPage(@PathVariable("id") Long id, Model model) {
        // 获取详情页所需要的数据
        Map<String, Object> map = pageService.loadItemData(id);
        // 设置数据到model中
        model.addAllAttributes(map);
        return "item";
    }
}
